{extend name="admin/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css">
.article_head label{float:left;margin-right:20px;width:120px;font-weight:normal;line-height: 32px;color:#333;font-size:13px; text-align: right;}
.article_head>div{width:97%;overflow: hidden;}
.article_head>div.content_ue{width:100%;height:420px;}
.textarea{width:70%;height:100px;max-width:70%;max-height:100px;}
.at_img{width:97%;height:135px;}
.at_btn{color: #FFF;background-color: #01B044;border-color: #01B044;font: normal 12px/20px "microsoft yahei";text-decoration: NONE; height: 35px; padding: 8px 10px;border: solid 1px;cursor: pointer;}
.ncsc-upload-btn{}
.class-logo{background-color: #F8F8F8;}
dd {margin-left: 0px;}
dl{margin-bottom:0px;}
input[type="radio"], input[type="checkbox"] { margin: 0 0 0;}
.required{color:red;margin-right:10px;}
.ar_top{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;}
.article_head h3{margin: 0 0 10px 0;line-height: 30px;font-size: 14px;font-weight: bold;color: #333;padding-left: 10px;}
.ar_center{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;}
.ar_bottom{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;margin-bottom:30px;}
.ke-inline-block{display: none;vertical-align: middle;zoom: 0;}
#image_file {width: 400px;}
input[type="file"]{border: none;}
.error{height: 32px;line-height: 32px;}
</style>
{/block}
{block name="main"}
<!-- <form action="" method="post"> -->
<div class="article_head">
	<div class="ar_top">
		<h3>常规信息</h3>
		<div>
			<label><span class="required">*</span>文章标题</label>
			<input id="title" type="text" name="title" style="width:70%;"/>
			<span class="error">请输入文章标题</span>
		</div>
		
		<div>
			<label>文章短标题</label>
			<input id="short_title" type="text" style="width:50%;"/>
		</div>
		
		<div>
			<label >文章标签</label>
			<input id="tag" type="text" style="width:50%;"/>
		</div>
		
		<div class="at_img">
			<label>文章标题图片</label>
			<div style="float:left;">
				<dl>
					<dd>
						<div class="class-logo"><p><img id="imgLogo"></p></div>
						<div class="ncsc-upload-btn"> 
						<!-- 	<a href="javascript:void(0);" onclick="imgUpload()" >
								<span><input type="hidden" id="group_pic"/></span>
								<p><i></i>图片上传</p>
							</a> -->
							 <a href="javascript:void(0);">
							 <span><input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadImg" nc_type="change_store_label" type="file" onchange="imgUpload(this);"> </span>
			                 <p><i class="icon-upload-alt"></i>上传图片</p>
			                 </a>
			  				 <input type="hidden" id="Logo" value=""/> 
							
						</div>
						<p class="hint">
							<span style="color:orange;">建议使用宽200像素-高60像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
						</p>
					</dd>
				</dl>
			</div>
		</div>

		<div>
			<label>文章作者</label>
			<input id="author" type="text" name="author"/>
		</div>
		
		<div>
			<label >文章来源</label>
			<input id="source"  type="text"/>
		</div>
		
		<div>
			<label>文章来源链接</label>
			<input  id="url"  type="text"/>
		</div>
		
		<div>
			<label><span class="required">*</span>所属分类</label>
			<select id="class_id">
				<option value="0">请选择</option>
				{volist name="articleClassList['data']" id="vo"}
					{if condition="$vo.pid eq 0"}
					<option value="{$vo.class_id}">{$vo.name}</option>
						{volist name="articleClassList['data']" id="v1"}
				            {if condition="$v1.pid eq $vo.class_id"}
								<option value="{$v1.class_id}">&nbsp;&nbsp;&nbsp;&nbsp;{$v1.name}</option>
							{/if}
				        {/volist} 
					{/if}
				{/volist}
			</select>
			<span class="error">请选择分类</span>
		</div>
		
		
		
		<br/>

		<div>
			<label>文章关键字</label>
			<input id="keyword" type="text"/>
		</div>
		
		<div>
			<label>文章摘要</label>
			<textarea id="summary" rows="10" cols="10" class="textarea"></textarea>
		</div>
		
	</div>
	
	<div class="ar_center">
		<h3>文章内容</h3>
		<div class="content_ue">
			<label>文章内容</label>
			<textarea class="at_04 " id="content" name="g_body" style="width: 70%;height: 400px;overflow:hidden;visibility: hidden; display: none;"></textarea>
		</div>
		<div style="overflow: hidden;margin: 10px 0;">
		<label>文章附件</label>
			<div style="float:left;">
				<dl>
					<dd>
						<div class="class-logo"><p id="p_file_upload_input"></p></div>
						<div class="ncsc-upload-btn">
							<a href="javascript:void(0);">
								<span>
									<input class="input-file" id="file_upload_input" name="file_upload" type="file">
									<input type="hidden" id="hidden_file_upload_input" />
								</span>
								<p><i class="fa fa-cloud-upload text"></i>附件上传</p>
							</a>
						</div>
					</dd>
				</dl>
			</div>
		</div>
		<div>
			<label>相关文章</label>
			<input id="article_id_array" type="text"/>
		</div>
	</div>
	
	<div class="ar_bottom"> 
		<h3>文章阐述</h3>
		<div>
			<label>推荐</label> 
			<div style="margin-top:5px;float:left;"><input type="checkbox" value="" id="commend_flag"/></div>
		</div> 
		<div style="height: 37px;">
			<label>允许评论</label> 
			<div style="margin-top:5px;float:left;"><input type="checkbox" value="" id="comment_flag"/></div>
		</div> 
		<div>
			<label>文章排序</label>
			<input id="sort" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章点击量</label>
			<input id="click" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章评论数</label> 
			<input id="comment_count" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章分享数</label>
			<input id="share_count" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
	</div> 
	<div style="margin:auto;width:30%;">
		<button class="edit_button" onclick="save(1)" style="float:left;margin-right:15px;">发布文章</button>
		<button class="edit_button" onclick="save(2)" style="float:left;">发布并预览</button>
	</div>
</div>
<!--</form> -->
{/block}
{block name="script"}
<script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
<script src="__STATIC__/kindeditor/lang/zh_cn.js" charset="utf-8"></script>
<script type="text/javascript">
$("#file_upload_input").live("change",function(){
	var data = { 'file_path' : UPLOADCOMMON };
	uploadFile("file_upload_input",data,function(res){
		if(res.code){
			$("#p_file_upload_input").text("文章附件");
			$("#hidden_file_upload_input").val("文章附件");
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
});
var KE;
KindEditor.ready(function(K) {
	KE = K.create("textarea[name='g_body']",{
		items : [
			'source',
			'|',
			'fullscreen',
			'undo',
			'redo',
			'print',
			'cut',
			'copy',
			'paste',
			'plainpaste',
			'wordpaste',
			'|',
			'justifyleft',
			'justifycenter',
			'justifyright',
			'justifyfull',
			'insertorderedlist',
			'insertunorderedlist',
			'indent',
			'outdent',
			'subscript',
			'superscript',
			'|',
			'selectall',
			'clearhtml',
			'quickformat',
			'|',
			'formatblock',
			'fontname',
			'fontsize',
			'|',
			'forecolor',
			'hilitecolor',
			'bold',
			'italic',
			'underline',
			'strikethrough',
			'lineheight',
			'removeformat',
			'|',
			'image',
			'flash',
			'media',
			'table',
			'hr',
			'emoticons',
			'link',
			'unlink',
			'|',
			'about'
		],
		cssPath : "__STATIC__/kindeditor/themes/default/default.css",
		allowImageUpload : false,
		allowFlashUpload : false,
		allowMediaUpload : false,
		allowFileManager : false,
		syncType : "form",
		afterCreate : function() {
			var self = this;
			self.sync();
		},
		afterChange : function() {
			var self = this;
			self.sync();
		},
		afterBlur : function() {
			var self = this;
			self.sync();
		}
	});
	KE.appendHtml = function(id,val) {
		this.html(this.html()+ val);
		if (this.isCreated) {
			var cmd = this.cmd;
			cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
			cmd.select();
		}
		return this;
	}
});
function validation(){
	var title=$("#title");//文章标题
	var class_id=$("#class_id");//所属分类
	if(title.val() == ""){
		title.next().css("display","inline-block");
		title.focus();
		return false;
	}else{
		$('.error').hide();
	}
	
	if(class_id.val() == 0){
		class_id.next().css("display","inline-block");
		class_id.focus();
		return false;
	}else{
		$('.error').hide();
	}
	return true;
}


var flag = false;//防止重复提交
function save(type){
	if(!validation()){
		return;
	}
	var comment_flag=$('#comment_flag').is(':checked')?'1':'0';
	var commend_flag=$('#commend_flag').is(':checked')?'1':'0';
	var title=$("#title").val();
	var class_id=$("#class_id").val();
	var short_title=$("#short_title").val();
	var source=$("#source").val();
	var url=$("#url").val();
	var author=$("#author").val();
	var summary=$("#summary").val();
	var content=$("#content").val();
//	var image=$("#imgLogo").attr("data-id");
    var image=$("#Logo").val();
	var keyword=$("#keyword").val();
	var article_id_array=$("#article_id_array").val();
	var click=$("#click").val();
	var sort=$("#sort").val();
	var tag=$("#tag").val();
	var comment_count=$("#comment_count").val();
	var share_count=$("#share_count").val();
	var attachment_path = $("#hidden_file_upload_input").val();
	if(flag){
		return;
	}
	flag = true;
	$.ajax({
		type:"post",
		url:"ADMIN_MAIN/Cms/addArticle",
		data:{
			'title':title,
			'class_id':class_id,
			'short_title':short_title,
			'source':source,
			'url':url,
			'author':author,
			'summary':summary,
			'content':content,
			'image':image,
			'keyword':keyword,
			'article_id_array':article_id_array,
			'click':click,
			'sort':sort,
			'commend_flag':commend_flag,
			'comment_flag':comment_flag,
			'attachment_path':attachment_path,
			'tag':tag,
			'comment_count':comment_count,
			'share_count':share_count,
			},
		success:function(data){
			if (data["code"] > 0) {
				showMessage('success', data["message"]);
				if(type==1){
					location.href="ADMIN_MAIN/cms/articlelist";
				}
				if(type==2){
					window.open("SHOP_MAIN/cms/articleclassinfo?article_id="+data['code']);
				}
			}else{
				showMessage('error', data["message"]);
			}
			flag = false;
		}
	});
}

//图片上传
// function imgUpload(){
// 	OpenPricureDialog("PopPicure", 'ADMIN_MAIN',1);
// }
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADCMS };
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#imgLogo").attr("src","__UPLOAD__/"+res.data);
			$("#Logo").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

// function PopUpCallBack(img_id,img_src){
// 	$("#imgLogo").attr("src",img_src);
// 	$("#imgLogo").attr("data-id",img_id);
//  }

/**
 * 删除文件
 * @param {Object} file_url
 * @param {Object} even
 */
function delete_file(file_url,even){
	$.ajax({
		type:"post",
		url:"ADMIN_MAIN/system/delete_file",
		data:{'file_url':file_url},
		async : true,
		dataType:'json',
		success:function(data){
			if (data['code']>0) {
				$( "#dialog" ).dialog({
					buttons: {
						"确定,#01B044": function() {
							$(this).dialog('close');
						}
					},
					contentText:"附件移除成功",
						time:1,
				});
				$(even).parent().empty();
			}else{
				$( "#dialog" ).dialog({
					buttons: {
						"确定,#e57373": function() {
							$(this).dialog('close');
						}
					},
					contentText:data['message'],
				});
			}
		}
	});
} 
</script>
{/block}